[#import "/framework/JGP.htm"  as JGP]
<!--
项目   jgp-cloud-parent
作者   LOUFEI [Gavin]
时间   2019/1/4
-->
[@JGP.head "选择角色或部门"/]
[@JGP.body]
    <jgp-div _row="['40','*']" _runit="px">
        <jgp-div slot="1-1" _col="['80','*']" _cunit="px">
            <jgp-btn slot="1-1" _fn="selectedOk">确定</jgp-btn>
            <jgp-form _id="form" slot="1-2">
                <jgp-radio _col="12" _name="fnc" _label="权限" _value="RW" _list="[{'label':'只读','value':'R'},{'label':'读写','value':'RW'}]"></jgp-radio>
            </jgp-form>
        </jgp-div>
        <jgp-div slot="2-1" _col="['*','10','*']" _cunit="px" >
            <jgp-div slot="1-1" _row="['*','*']" _aux="true">
                <jgp-panel slot="1-1" _title="<a style='color:gray;'>系统角色</a>" _default_tools="[]">
                    <jgp-tree2 _root="系统角色" _single="true" _check="false"
                               _show_root="false"
                               _tools="[{'name':'==>','tip':'添加到选择列表','fn':'doSelectRoleFn'}]"
                               _url="/security/role-api-ctl/query-tree"></jgp-tree2>
                </jgp-panel>
                <jgp-panel slot="2-1" _title="<a style='color:gray;'>系统部门</a>" _default_tools="[]">
                    <jgp-tree2 _root="系统部门" _single="true" _check="false"
                               _show_root="false"
                               _tools="[{'name':'==>','tip':'添加到选择列表','fn':'doSelectOrgFn'}]"
                               _url="/security/institution-api-ctl/query-tree"></jgp-tree2>
                </jgp-panel>
            </jgp-div>
            <jgp-div  slot="1-3" _row="['*','*']"  _aux="true">
                <jgp-panel slot="1-1" _title="<a style='color:green;'>已选择角色</a>" _default_tools="[]">
                    <jgp-div _row="['40','*']" _runit="px" >
                        <jgp-form _id="form-role" slot="1-1">
                            [#--<jgp-radio _col="12" _name="scope" _label="授权范围" _value="ROLE" _list="[{'label':'当前角色','value':'ROLE'},{'label':'当前及下级角色','value':'ROLE_DOWN'}]"></jgp-radio>--]
                            [#--<jgp-radio _col="12" _name="fnc" _label="权限" _value="RW" _list="[{'label':'只读','value':'R'},{'label':'读写','value':'RW'}]"></jgp-radio>--]
                        </jgp-form>
                        <jgp-list slot="2-1" _id="selectedRoleList" _unique="true" _wrapper="title:name,key:id"></jgp-list>
                    </jgp-div>
                </jgp-panel>
                <jgp-panel slot="2-1" _title="<a style='color:green;'>已选择部门</a>" _default_tools="[]">
                    <jgp-div _row="['40','*']" _runit="px" >
                        <jgp-form _id="form-org" slot="1-1">
                            [#--<jgp-radio _col="12" _name="scope" _label="授权范围" _value="ORG" _list="[{'label':'当前机构','value':'ORG'},{'label':'当前及下级机构','value':'ORG_DOWN'}]"></jgp-radio>--]
                            [#--<jgp-radio _col="12" _name="fnc" _label="权限" _value="RW" _list="[{'label':'只读','value':'R'},{'label':'读写','value':'RW'}]"></jgp-radio>--]
                        </jgp-form>
                        <jgp-list slot="2-1" _id="selectedOrgList" _wrapper="title:name,key:id"></jgp-list>
                    </jgp-div>
                </jgp-panel>
            </jgp-div>
        </jgp-div>
    </jgp-div>

[/@JGP.body]

[@JGP.foot]
    <script>
        function doSelectRoleFn(args) {
            JGP.list('selectedRoleList').setList([args.back.node.bean])
        }

        function doSelectOrgFn(args){
            JGP.list('selectedOrgList').setList([args.back.node.bean])
        }

        function selectedOk(){
            var roles = JGP.list('selectedRoleList').getAllRecords();
            var orgs = JGP.list('selectedOrgList').getAllRecords();
            var form = JGP.form('form');
            var fnc = form.field('fnc');
            var item = {};
            if(roles[0]&&orgs[0]){
                item.value = 'ORG:'+orgs[0].id+',ROLE:'+roles[0].id;
                item.label = '【部门】:'+orgs[0].name+',【角色】:'+roles[0].name
            }else if(roles[0]&&!orgs[0]){
                item.value = 'ROLE:'+roles[0].id;
                item.label = '【角色】:'+roles[0].name
            }else if(!roles[0]&&orgs[0]){
                item.value = 'ORG:'+orgs[0].id;
                item.label = '【部门】:'+orgs[0].name
            }else {
                item = undefined;
            }
            if(item){
                if(fnc == 'R'){
                    item.label += '(只读)'
                    item.value = 'R:'+item.value;
                }

                JGP.$close(item)
            }else {
                JGP.$close();
            }
        }
    </script>
[/@JGP.foot]